package Reeks5.VanRansbeeck.Kevin.View;

import java.awt.*;
import javax.swing.*;

class StatesCellRenderer extends JPanel implements ListCellRenderer{
    JLabel left, middle, right;
    
    public StatesCellRenderer() {
        setLayout(new GridLayout(1, 3));
        left = new JLabel();
        middle	= new JLabel();
        right = new JLabel();
        left.setOpaque(true);
        middle.setOpaque(true);
        right.setOpaque(true);
        add(left);
        add(middle);
        add(right);
    }
    
    public Component getListCellRendererComponent(JList list,Object value,int index,boolean isSelected,boolean cellHasFocus){
        String leftData = ((String[])value)[0];
        String middleData = " => ";
        String rightData = ((String[])value)[1];
        left.setText(leftData);
        middle.setText(middleData);
        right.setText(rightData);
        if(isSelected){
            left.setBackground(list.getSelectionBackground());
            left.setForeground(list.getSelectionForeground());
            middle.setBackground(list.getSelectionBackground());
            middle.setForeground(list.getSelectionForeground());
            right.setBackground(list.getSelectionBackground());
            right.setForeground(list.getSelectionForeground());
        }
        else{
            left.setBackground(list.getBackground());
            left.setForeground(list.getForeground());
            middle.setBackground(list.getBackground());
            middle.setForeground(list.getForeground());
            right.setBackground(list.getBackground());
            right.setForeground(list.getForeground());
        }
        setEnabled(list.isEnabled());
        setFont(list.getFont());
        return this;
    }
}